<?php
include ('chek.php');
//修改用户名或密码
$aid=$input->get('aid');
$a_user=array(
    'auser'=>'',
    'apass'=>'',
);
if($aid>0){
    $sql="select * from admin WHERE aid='{$aid}'";
    $row=$db->query($sql);
    $a_user=$row->fetch_array(MYSQLI_ASSOC);
}
if($input->get('do')=='add'){
    $user=$input->post('auser');
    $pass=$input->post('apass');
    if(empty($user) || empty($pass)){
        die('用户名或密码不能为空！');
    }
    //检查用户名是否重复
    $sq="select * from admin WHERE auser='{$user}' and aid <> '{$aid}'";
    $res=$db->query($sq);
    if($res->fetch_array()){
        die('用户名不能重复！');
    }
    if($aid>0){
        $sql="update admin set auser='{$user}',apass='$pass' WHERE aid='{$aid}'";
    }
    else{
        $sql="insert into admin (auser,apass) VALUE ('{$user}','{$pass}')";
    }
    $is=$db->query($sql);
    if($is){
        header('location:auser.php');
    }
    else{
        die('执行失败！');
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>管理员管理</title>
    <?php include (PATH.'/headr.php') ?>
</head>
<body>
<?php include ('nac.inc.php'); ?>
<div class="container">
    <div class="row">
        <h2>管理员管理<small class="pull-right"><a class="btn btn-default" href="auser.php">返回</a></small></h2>
        <hr/>
        <form class="form-horizontal" action="auser_add.php?do=add&aid=<?php echo $aid;?>" method="post">
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
                <div class="col-sm-6">
                    <input type="text" name="auser" class="form-control" id="inputEmail3" placeholder="请输入用户名" value="<?php echo $a_user['auser']?>">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
                <div class="col-sm-6">
                    <input type="password" name="apass" class="form-control" id="inputPassword3" placeholder="请输入密码" value="<?php echo $a_user['apass']?>">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <button type="submit" class="btn btn-default">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>